package cn.ly.objdata;

public class Person {
	private String lastName;
	private String firstName;
	private int age;
	
	public Person(String last,String first,int age){
		this.lastName = last;
		this.firstName = first;
		this.age = age;
	}
	
	public Person(){
		
	}
	
	public void displayPerson(){
		System.out.println(this.toString());
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Person ["+firstName + lastName + ", age=" + age + "]";
	}
	
	public int compare(Person p){
		int result = 0;
		if( (result = this.firstName.compareTo(p.firstName)) == 0){
			if( (result = this.lastName.compareTo(p.lastName)) == 0){
				//return Integer.compare(this.age, p.age);
				if(this.age > p.age){
					return 1;
				}else if(this.age == p.age){
					return 0;
				}else{
					return -1;
				}
			}
		}
		return result;
	}
	
	
}
